package com.raidpoints.client;

import java.util.ArrayList;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

public class RemoveCharacterBox extends DialogBox {
	AccountPage ap;
	ArrayList<character> chars;
	public RemoveCharacterBox(AccountPage map) {
		ap = map;
		setHTML("Remove Character From Account");
		chars = new ArrayList<character>();
	
		
		LayoutPanel layoutPanel = new LayoutPanel();
		setWidget(layoutPanel);
		layoutPanel.setSize("100%", "117px");
		
		final ListBox comboBox = new ListBox();
		layoutPanel.add(comboBox);
		comboBox.setWidth("170px");
		layoutPanel.setWidgetLeftWidth(comboBox, 24.0, Unit.PX, 180.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(comboBox, 23.0, Unit.PX, 24.0, Unit.PX);
		
		for(character c : ap.chardataProvider.getList()) {chars.add(c); comboBox.addItem(c.name);}
		
		final AsyncCallback<String> removeCallback  = new AsyncCallback<String>(){

			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				hide();
			}

			@Override
			public void onSuccess(String result) {
				ap.Refresh();	
				hide();
			}
			
		};
		
		Button removeButton = new Button("Remove");
		removeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				if(comboBox.getSelectedIndex() >= 0) ap.rp.rpsvc.RemoveAccountChar(chars.get(comboBox.getSelectedIndex()), removeCallback);
				
			}
		});
		layoutPanel.add(removeButton);
		layoutPanel.setWidgetLeftWidth(removeButton, 20.0, Unit.PX, 81.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(removeButton, 73.0, Unit.PX, 28.0, Unit.PX);
		
		Button cancelButton = new Button("Cancel");
		layoutPanel.add(cancelButton);
		layoutPanel.setWidgetLeftWidth(cancelButton, 121.0, Unit.PX, 81.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(cancelButton, 73.0, Unit.PX, 28.0, Unit.PX);
		cancelButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				hide();
			}
		});
	}
}
